package org.example;

import java.util.Optional;
import java.util.StringJoiner;

public record User(String name, String email, Integer age, String password) implements IObjectPrinter {

    public User {
        if (age < 0) {
            throw new IllegalArgumentException("Age cannot be negative");
        }
    }

    public User(String name) {
        this(name, null, null, null);
    }

    public String concat() {
        return name + " " + email + " " + age + " " + password;
    }

    public static String emailToUpperCase(String email) {
        return Optional.ofNullable(email).orElse("no email").toUpperCase();
    }

    @Override
    public String print() {
        StringJoiner sj = new StringJoiner("-");
        return sj.add(name).add(email).add(age.toString()).toString();
    }
}
